import { Component, OnInit } from '@angular/core';
import {StudentService} from "../student-detail/student.service";
import {TongJiGender} from "../student";

@Component({
  selector: 'app-student-echar-demo',
  templateUrl: './student-echar-demo.component.html',
  styleUrls: ['./student-echar-demo.component.css']
})
export class StudentEcharDemoComponent implements OnInit {

  option = null
  /*option = {
    title : {
      text: '学员性别比例',
      subtext: '纯属虚构',
      x:'center'
    },
    tooltip : {
      trigger: 'item',
      formatter: "{a} <br/>{b} : {c} ({d}%)"
    },
    legend: {
      orient: 'vertical',
      left: 'left',
      data: ['男','女']
    },
    series : [
      {
        name: '性别比例',
        type: 'pie',
        radius : '55%',
        center: ['50%', '60%'],
        data:[
          {value:335, name:'男'},
          {value:310, name:'女'},

        ],
        itemStyle: {
          emphasis: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        }
      }
    ]
  };*/
  constructor(private studentService:StudentService) { }

  ngOnInit() {
    this.tongji()
  }
  tongji(){
    this.studentService.gender().subscribe(tg=>{
      var ldata:string[]=[]
      var sdata=[]
      tg.forEach((v,i)=>{
        ldata.push(v.title)
        sdata.push({value:v.count,name:v.title})
      })
      /*this.option.legend.data=ldata
      this.option.series[0].data=sdata*/
      this.option={
        title : {
          text: '学员性别比例',
          subtext: '纯属虚构',
          x:'center'
        },
        tooltip : {
          trigger: 'item',
          formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
          orient: 'vertical',
          left: 'left',
          data:ldata
        },
        series : [
          {
            name: '性别比例',
            type: 'pie',
            radius : '55%',
            center: ['50%', '60%'],
            data:sdata,
            itemStyle: {
              emphasis: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      }
    })
  }
}
